/*
 * @Copyright: (C) 2019 Zhang Rida. All rights reserved.
 *
 * @Author: Zhang Rida
 * @Email: 215154317@qq.com
 * @FilePath: /WEILA_SDK_MODULE/include/wl_audio.h
 * @Date: 2021-02-23 18:23:03
 * @Description: message for weila osal
 *
 * @LastEditors: Zhang Rida
 * @LastEditTime: 2022-04-27 19:11:48
 */
#ifndef _WL_AUDIO_H
#define _WL_AUDIO_H

#include "wl_types.h"

#define AUDIO_VOIP_SUPPORT 0        // VOIP支持表示录播可同时进行
#define PLAYER_FINISH_WAIT_FRAMES 5 // 某些平台播放结束后要等待一段时间,否则会丢尾音
#define TTS_SUPPORT 0

#define RECORD_PCM_RATE 16000
#define PLAY_PCM_RATE 16000
#undef AUDIO_VOIP_SUPPORT
#define AUDIO_VOIP_SUPPORT 0
#undef TTS_SUPPORT
#define TTS_SUPPORT 1
typedef void *WL_AUDIO_HANDLE;

#define RECORD_PCM_FRAME_BYTES ((RECORD_PCM_RATE / 50) << 1)
#define RECORD_PCM_FRAME_LEN (RECORD_PCM_RATE / 50)
#define PLAY_PCM_FRAME_BYTES ((PLAY_PCM_RATE / 50) << 1)
#define PLAY_PCM_FRAME_LEN (PLAY_PCM_RATE / 50)
// PCM录音缓存区最多缓存2帧数据即可
#define RECORD_PCM_CACHED_LEN (RECORD_PCM_FRAME_BYTES << 1)
// PCM播放缓存区
#define PLAY_PCM_CACHED_LEN (PLAY_PCM_FRAME_BYTES << 1)

typedef enum
{
    WL_AUDIO_PLAYER_END_FINISHED,
    WLAUDIO_PLAYER_END_MANUAL
} WL_AUDIO_PLAYER_END_REASON;

typedef void (*wl_audio_recorder_callback)(WL_AUDIO_HANDLE handle, const wl_uint8 *data, wl_uint32 data_size);
typedef void (*wl_audio_player_callback)(WL_AUDIO_HANDLE handle);
typedef void (*wl_audio_end_callback)(WL_AUDIO_HANDLE handle, wl_int32 result); // result 0 正常结束 -1 异常结束

wl_int32 wl_audio_init(void);
wl_int32 wl_audio_end(void);
WL_AUDIO_HANDLE wl_audio_start_record(wl_audio_recorder_callback callback, wl_audio_end_callback end_callback);
wl_int32 wl_audio_stop_record(WL_AUDIO_HANDLE handle);
WL_AUDIO_HANDLE wl_audio_start_play(wl_audio_player_callback callback, wl_audio_end_callback end_callback);
wl_int32 wl_audio_stop_play(WL_AUDIO_HANDLE handle);
wl_int32 wl_audio_put_play_data(WL_AUDIO_HANDLE handle, wl_uint8 *data, wl_uint32 data_size);

#endif // _WL_AUDIO_H
